#include <iostream>
using std::cout;
using std::endl;
//基类和派生类之间的相互转换工作
class Base{

private:
    long _base = 10;
};
class Derived: public Base{
private:
    long _derived = 20;
};
void test(){
    Base b;
    Derived d;
    //基类和派生类对象之间相互赋值
    b = d;//把一个派生类对象转换成基类对象ok
    //d = b;error
    Base * pbase = &d;//一个基类指针指向派生类对象ok
    //Derived * pderived = &b;error 
    Base & ref1 = d;//一个基类的引用去绑定派生类对象ok
    //Derived & ref2 = b;error 
}

void test2(){
    cout << sizeof(Base) << endl;// 8
    cout << sizeof(Derived) << endl;// 16
    //创建了一个Base*指针，
    //指向了当前堆区base对象的首地址
    //并且该指针能够操作的内存空间是多大？？8字节
    //同理，Derived *指针能够操作的空间是多大？16字节
    Base * pBase = new Base();
    Derived * pderived = new Derived();



    delete pBase;
    delete pderived;
    pBase = nullptr;
    pderived = nullptr;
}

int main()
{
    test2();
    return 0;
}

